package com.demo.common.file;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件处理service,使用了装饰者模式
 */
@Component
public class FileService {

    /**
     * 实际使用的文件处理service
     */
    @Resource
    private FileOperator fileOperator;

    /**
     * 上传文件
     * @param multipartFile
     * @return
     */
    public String uploadFile(MultipartFile multipartFile){
        return fileOperator.upload(multipartFile);
    }

    /**
     * 下载文件
     * @param fileName
     * @param response
     */
    public void downLoadFile(String fileName, HttpServletResponse response){
        fileOperator.downLoad(fileName,response);
    }

    /**
     * 删除文件
     * @param fileName
     */
    public void deleteFile(String fileName){
        fileOperator.delete(fileName);
    }

}
